Django Web Development with Python - Dynamic URLS

by: vugar, 7 years ago


Hi . I faced a problem creating dynamic urls for blog page. I added two blog page in my website (blog and news). For blog everything is ok but for news, problem on DetailView url.
My blog page urls is :

from django.conf.urls import url, include
from django.views.generic import ListView, DetailView
from blog.models import Post
urlpatterns = [url(r'^$',ListView.as_view(queryset=Post.objects.all().order_by("date")[:25],
                                                                                         template_name="blog/blog.html")),
                        url(r'^(?P<pk>d+)$', DetailView.as_view(model=Post,
                                                                           template_name='blog/post.html'))]

And my news page urls is :

from django.conf.urls import url, include
from django.views.generic import ListView, DetailView
from news.models import New
urlpatterns = [ url(r'^$', ListView.as_view(queryset=New.objects.all().order_by("-date")[:25],
                                                               template_name="news/news.html")),
                        url(r'^(?P<pk>d+)$',DetailView.as_view(model=New,
                                                              template_name='news/new.html'))]

When click News button ,list of news open with news/  url. But then click on news to open it as detail view it should be news/1 ,but opened blog/1 url and open blog page.

Please help me to solve this problem , thanks beforehand
    




You must be logged in to post. Please login or register an account.



I found problem and solved it.Problem was in templates file for news page

-vugar 7 years ago
Last edited 7 years ago

You must be logged in to post. Please login or register an account.